const http = require('http');
const fs = require('fs');
const path = require('path');

const server = http.createServer();
server.on('request',(req,res)=>{
  const url = req.url;
  let fpath;
  if(url === '/'){
    fpath = path.join(__dirname,'/clock/test.html')
  }else{
    fpath = path.join(__dirname,'/clock',url)
  }
  fs.readFile(fpath,'utf8',(err,dataStr)=>{
    if(err) return console.log(err.message);
    res.end(dataStr)
  })
  res.setHeader('Content-Type','text/html;charset=utf-8');
})
server.listen(3000,()=>{
  console.log('服务启动成功');
})